<%@ tag pageEncoding="UTF-8" %>
<%@ attribute name="totalPage" required="true" type="java.lang.Integer" rtexprvalue="true" description="总页数" %>
<%@ attribute name="currentPage" required="false" type="java.lang.Integer" rtexprvalue="true" description="当前页码" %>
<%@ attribute name="url" required="false" rtexprvalue="true" description="url" %>
<%	
	if(currentPage==null){		
		currentPage = 1;
	}
	if(url==null){
		url = "#";
	}else{
		if(url.indexOf("?")!=-1){
			url += "&page={page}";
		}
	}
	int currentPageI = currentPage.intValue();
	int totalPageI = totalPage.intValue();
	
	StringBuilder pagerSB =  new StringBuilder();
	pagerSB.append("<div class=\"pager\"><span>总共 "+totalPageI+" 页, </span>");
	if(totalPageI>1&&currentPageI>1){
		pagerSB.append("<a href=\""+url.replace("{page}", "1")+"\" class=\"fcbl uLine mrs\" page=\"1\">首页</a>");
	}
	int i=1,j=10;
	if(totalPageI>10){
		if(currentPageI+5>totalPageI){
			i = totalPageI - 9;
			j = totalPageI;
		}else if(currentPageI-4>=1){
			i = currentPageI - 4;
			j = currentPageI + 5;
		}
	}else{
		j = totalPageI;
	}
	for(;i<=j;i++){
		if(i==currentPageI){
			pagerSB.append("<a href=\""+url.replace("{page}", i+"")+"\" class=\"bold fco mrs\" page=\""+i+"\">"+i+"</a>");
		}else{
			pagerSB.append("<a href=\""+url.replace("{page}", i+"")+"\" class=\"fcbl uLine mrs\" page=\""+i+"\">"+i+"</a>");
		}
	}
	if(currentPageI!=totalPageI){
		pagerSB.append("<a href=\""+url.replace("{page}", (currentPageI+1)+"")+"\" class=\"fcbl uLine mrs\" page=\""+(currentPageI+1)+"\">下一页</a>");
		pagerSB.append("<a href=\""+url.replace("{page}", totalPageI+"")+"\" class=\"fcbl uLine mrs\" page=\""+totalPageI+"\">末页</a>");
	}
	pagerSB.append("</div>");
	out.println(pagerSB.toString());
	if("#".equals(url)){
%>
<script type="text/javascript">
	$(document).ready(function() {
		//绑定上下页的事件操作,此处要保证url带的参数page要在最后
		$(".pager a").click(function() {
			var page = $(this).attr("page");
			var url = window.location.href;
			if(url.lastIndexOf("#")==url.length-1){
				url = url.substring(0,url.length-1);
			}
			if(url.indexOf("?") == -1){
				url += "?currentPage="+page;
			}else{
				var index = url.indexOf("currentPage=");
				if (index != -1) {
					url = url.substring(0, index);
				}
				url += "currentPage=" + page;
			}
			window.location.href = url;
		});
	});
</script>
<%}%>